package cn.virens.config;

import java.io.IOException;

import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.session.web.http.HttpSessionIdResolver;

import cn.virens.utils.ResourceUtil;
import cn.virens.web.components.session.resolver.OrderHttpSessionIdResolver;

@Configuration
@EnableCaching
@EnableScheduling
@ComponentScan({ "cn.virens.web.components.open.wxmp", "cn.virens.web.components.open.oauth" })
@Import(value = { SpringCacheEhcacheConfig.class, SpringDataSourceConfig.class, SpringShiroConfig.class })
public class ServletRootConfig {
	/**
	 * Session ID 管理
	 * 
	 * @return
	 */
	@Bean
	public HttpSessionIdResolver httpSessionIdResolver() {
		return new OrderHttpSessionIdResolver();
	}

	/** 注入配置文件 */
	@Bean("propertyPlaceholderConfigurer")
	public static PropertySourcesPlaceholderConfigurer propertyPlaceholderConfigurer() throws IOException {
		PropertySourcesPlaceholderConfigurer configurer = new PropertySourcesPlaceholderConfigurer();
		configurer.setLocations(ResourceUtil.getResources("classpath:config/*.properties"));
		configurer.setIgnoreUnresolvablePlaceholders(true);

		return configurer;
	}
}
